package com.xcdh.commons.utils;

import java.time.LocalDateTime;
import java.util.*;

public class TypeMap {
    private static final Map<List<String>,String> TYPE = new HashMap<>() ;
    private static final String STRING_KEY = "String" ;
    static {
        List<String> inter = ListUtil.asList("tinyint","smallint","mediumint","int","integer") ;
        List<String> date = ListUtil.asList("date","timestamp") ;
        TYPE.put(inter,"Integer");
        TYPE.put(Collections.singletonList("bigint"),"Long");
        TYPE.put(Collections.singletonList("float"),"Float");
        TYPE.put(Collections.singletonList("double"),"Double");
        TYPE.put(Collections.singletonList("decimal"),"BigDecimal");
        TYPE.put(Collections.singletonList("bit"),"Boolean");
        TYPE.put(date,"LocalDate");
        TYPE.put(Collections.singletonList("datetime"),"LocalDateTime");

    }
    public static String getJavaType(String jdbcType){
        Set<Map.Entry<List<String>, String>> entries = TYPE.entrySet();
        for (Map.Entry<List<String>, String> entry : entries) {
            if(entry.getKey().contains(jdbcType)){
                return entry.getValue() ;
            }
        }
        return STRING_KEY ;
    }
}
